-
Notifications
You must be signed in to change notification settings - Fork 1
Nxd 32 - Deploy Backend & Frontend via Self Host #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes the following error, when running `npm run dev` in the backend:
```
/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:859
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript:
src/models/user_model.ts:34:13 - error TS2322: Type 'unknown' is not assignable to type 'string'.
34 id: ret._id,
~~
src/types/user_types.ts:13:5
13 id: string;
~~
The expected type comes from property 'id' which is declared here on type 'UserData'
src/models/user_model.ts:35:13 - error TS2322: Type 'unknown' is not assignable to type 'string'.
35 username: ret.username,
~~~~~~~~
src/types/user_types.ts:14:5
14 username: string;
~~~~~~~~
The expected type comes from property 'username' which is declared here on type 'UserData'
src/models/user_model.ts:36:13 - error TS2322: Type 'unknown' is not assignable to type 'string'.
36 email: ret.email,
~~~~~
src/types/user_types.ts:15:5
15 email: string;
~~~~~
The expected type comes from property 'email' which is declared here on type 'UserData'
src/models/user_model.ts:37:13 - error TS2322: Type 'unknown' is not assignable to type 'string'.
37 password: ret.password,
~~~~~~~~
src/types/user_types.ts:16:5
16 password: string;
~~~~~~~~
The expected type comes from property 'password' which is declared here on type 'UserData'
src/models/user_model.ts:38:13 - error TS2322: Type 'unknown' is not assignable to type 'string | undefined'.
38 imageFilename: ret?.imageFilename,
~~~~~~~~~~~~~
src/types/user_types.ts:17:5
17 imageFilename?: string;
~~~~~~~~~~~~~
The expected type comes from property 'imageFilename' which is declared here on type 'UserData'
src/models/user_model.ts:39:13 - error TS2322: Type 'unknown' is not assignable to type 'string | undefined'.
39 createdAt: ret.createdAt,
~~~~~~~~~
src/types/user_types.ts:18:5
18 createdAt?: string,
~~~~~~~~~
The expected type comes from property 'createdAt' which is declared here on type 'UserData'
src/models/user_model.ts:40:13 - error TS2322: Type 'unknown' is not assignable to type 'string | undefined'.
40 updatedAt: ret.updatedAt
~~~~~~~~~
src/types/user_types.ts:19:5
19 updatedAt?: string,
~~~~~~~~~
The expected type comes from property 'updatedAt' which is declared here on type 'UserData'
at createTSError (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:859:12)
at reportTSError (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:863:19)
at getOutput (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1077:36)
at Object.compile (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1433:41)
at Module.m._compile (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1617:30)
at node:internal/modules/cjs/loader:1895:10
at Object.require.extensions.<computed> [as .ts] (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1465:32)
at Function._load (node:internal/modules/cjs/loader:1282:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
diagnosticCodes: [
2322, 2322,
2322, 2322,
2322, 2322,
2322
]
}
[nodemon] app crashed - waiting for file changes before starting...
```
**Problem**
In `user_model.ts`, the `transform` function is typed
to return `UserData`, which expects all fields to be
of type `string` (or `string | undefined` for some).
However, the `ret` object passed to the transform
function is not strongly typed—it is inferred as
`any` or `unknown` by TypeScript, especially when
using strict settings.
This fixes all the models` `transform` function.
Signed-off-by: Tal Jacob <taljacob2@gmail.com>
Fixes the following error, when running the backend:
```
/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:859
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript:
src/models/user_model.ts:34:17 - error TS18046: 'ret._id' is of type 'unknown'.
34 id: ret._id.toString(),
~~~~~~~
src/models/user_model.ts:39:54 - error TS2339: Property 'toISOString' does not exist on type '{}'.
39 createdAt: ret.createdAt ? ret.createdAt.toISOString() : undefined,
~~~~~~~~~~~
src/models/user_model.ts:40:54 - error TS2339: Property 'toISOString' does not exist on type '{}'.
40 updatedAt: ret.updatedAt ? ret.updatedAt.toISOString() : undefined
~~~~~~~~~~~
at createTSError (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:859:12)
at reportTSError (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:863:19)
at getOutput (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1077:36)
at Object.compile (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1433:41)
at Module.m._compile (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1617:30)
at node:internal/modules/cjs/loader:1895:10
at Object.require.extensions.<computed> [as .ts] (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1465:32)
at Function._load (node:internal/modules/cjs/loader:1282:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
diagnosticCodes: [ 18046, 2339, 2339 ]
}
[nodemon] app crashed - waiting for file changes before starting...
```
This tells TypeScript that `ret` is an object with
string keys and any values, so you can safely
access properties and call methods like
`.toString()` and `.toISOString()`.
The root cause of the error is that in the
user_model.ts, the ret parameter in the
transform function is not typed,
so TypeScript infers it as unknown.
This is why you get errors like 'ret._id'
is of type 'unknown' and 'toISOString'
does not exist on type '{}'.
Other models (like posts, comments, company)
fix this by typing ret as Record<string, any>.
The fix has been applied the ret parameter
in the user_model.ts transform function
is now typed as Record<string, any>.
This will resolve the TypeScript errors about
unknown and {} types for ret._id and date fields.
Signed-off-by: Tal Jacob <taljacob2@gmail.com>
The Vite configuration has been updated to use the `VITE_DOMAIN_NAME` environment variable for the host in both the server and preview sections. Now, if the `.env` file sets `VITE_DOMAIN_NAME=0.0.0.0`, the frontend will be exposed on all network interfaces. Signed-off-by: Tal Jacob <taljacob2@gmail.com>
Signed-off-by: Tal Jacob <taljacob2@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See https://nextstepfinalproject.atlassian.net/browse/NXD-32